package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.service.INursingProjectService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理项目 Controller
 *
 * @author ruoyi
 * @date 2025-06-09
 */
@Api(tags = "护理项目管理", description = "提供护理项目的增删改查服务")
@RestController
@RequestMapping("/serve/project")
public class NursingProjectController extends BaseController
{
    @Autowired
    private INursingProjectService nursingProjectService;

    /**
     * 查询 护理项目 列表
     */
    @ApiOperation(value = "查询护理项目列表", notes = "根据条件分页查询护理项目信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "项目名称", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "status", value = "状态（0: 禁用，1: 启用）", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", defaultValue = "10")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = TableDataInfo.class),
            @ApiResponse(code = 403, message = "无权限访问"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @PreAuthorize("@ss.hasPermi('serve:project:list')")
    @GetMapping("/list")
    public TableDataInfo<List<NursingProject>> list(NursingProject nursingProject)
    {
        startPage();
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        return getDataTable(list);
    }

    /**
     * 导出 护理项目 列表
     */
    @ApiOperation(value = "导出护理项目列表", notes = "将符合条件的护理项目信息导出为Excel文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "项目名称", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "status", value = "状态（0: 禁用，1: 启用）", paramType = "query", dataType = "int")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "导出成功"),
            @ApiResponse(code = 403, message = "无权限访问"),
            @ApiResponse(code = 500, message = "导出失败")
    })
    @PreAuthorize("@ss.hasPermi('serve:project:export')")
    @Log(title = " 护理项目 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NursingProject nursingProject)
    {
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        ExcelUtil<NursingProject> util = new ExcelUtil<NursingProject>(NursingProject.class);
        util.exportExcel(response, list, " 护理项目 数据");
    }

    /**
     * 获取 护理项目 详细信息
     */
    @ApiOperation(value = "获取护理项目信息", notes = "根据项目ID获取护理项目的详细信息")
    @ApiParam(name = "id", value = "护理项目ID", required = true)
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = NursingProject.class),
            @ApiResponse(code = 403, message = "无权限访问"),
            @ApiResponse(code = 404, message = "项目不存在")
    })
    @PreAuthorize("@ss.hasPermi('serve:project:query')")
    @GetMapping(value = "/{id}")
    public R<NursingProject> getInfo(@PathVariable("id") Long id)
    {
        NursingProject nursingProject = nursingProjectService.selectNursingProjectById(id);
        return R.ok(nursingProject);
    }

    /**
     * 新增 护理项目
     */
    @ApiOperation(value = "新增护理项目", notes = "创建新的护理项目信息")
    @ApiParam(name = "nursingProject", value = "护理项目实体", required = true)
    @ApiResponses({
            @ApiResponse(code = 200, message = "新增成功"),
            @ApiResponse(code = 400, message = "参数错误"),
            @ApiResponse(code = 403, message = "无权限访问"),
            @ApiResponse(code = 500, message = "创建失败")
    })
    @PreAuthorize("@ss.hasPermi('serve:project:add')")
    @Log(title = " 护理项目 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NursingProject nursingProject)
    {
        return toAjax(nursingProjectService.insertNursingProject(nursingProject));
    }

    /**
     * 修改 护理项目
     */
    @ApiOperation(value = "修改护理项目信息", notes = "根据项目ID更新护理项目的详细信息")
    @ApiParam(name = "nursingProject", value = "护理项目实体，包含ID和要更新的字段", required = true)
    @ApiResponses({
            @ApiResponse(code = 200, message = "更新成功"),
            @ApiResponse(code = 400, message = "参数错误"),
            @ApiResponse(code = 403, message = "无权限访问"),
            @ApiResponse(code = 404, message = "项目不存在"),
            @ApiResponse(code = 500, message = "更新失败")
    })
    @PreAuthorize("@ss.hasPermi('serve:project:edit')")
    @Log(title = " 护理项目 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NursingProject nursingProject)
    {
        return toAjax(nursingProjectService.updateNursingProject(nursingProject));
    }

    /**
     * 删除 护理项目
     */
    @ApiOperation(value = "删除护理项目", notes = "根据项目ID数组批量删除护理项目")
    @ApiParam(name = "ids", value = "护理项目ID数组", required = true)
    @ApiResponses({
            @ApiResponse(code = 200, message = "删除成功"),
            @ApiResponse(code = 403, message = "无权限访问"),
            @ApiResponse(code = 404, message = "项目不存在"),
            @ApiResponse(code = 500, message = "删除失败")
    })
    @PreAuthorize("@ss.hasPermi('serve:project:remove')")
    @Log(title = " 护理项目 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nursingProjectService.deleteNursingProjectByIds(ids));
    }
}